package com.android.xunxian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.android.xunxian.R;
import com.android.xunxian.entry.GuanwType;
import com.android.xunxian.entry.JLTable;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by zouqh on 2016/8/8.
 */
public class GuanWTypeAdater extends BaseAdapter {
    private Context context;
    private List<GuanwType> jlTableList;
    private List<Boolean> falg;

    public GuanWTypeAdater(Context context, List<GuanwType> jlTableList, List<Boolean> falg) {
        this.context = context;
        this.jlTableList = jlTableList;
        this.falg=falg;
    }

    @Override
    public int getCount() {
        return this.jlTableList.size();
    }

    @Override
    public Object getItem(int position) {
        return jlTableList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.guanw_item, null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(jlTableList.get(position).getSELCON());

        viewHolder.checkbox.setChecked(falg.get(position));
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.name)
        TextView name;
        @InjectView(R.id.checkbox)
        CheckBox checkbox;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
